<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="物业名称" prop="pmid">
        <el-select v-model="queryParams.pmid" placeholder="请输入物业名称" clearable>
          <el-option
            v-for="item in carsManagement"
            :key="item.pmid"
            :label="item.propertyName"
            :value="item.pmid"
            @keyup.enter.native="handleQuery">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="车场名称" prop="hpid">
        <el-select v-model="queryParams.hpid" placeholder="请输入车场名称" clearable>
          <el-option
            v-for="item in carsHome"
            :key="item.chid"
            :label="item.chname"
            :value="item.chid"
            @keyup.enter.native="handleQuery">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="开关类型" prop="off">
        <el-select v-model="queryParams.off" placeholder="请选择开关类型" clearable >
          <el-option label="开闸" value="0" @keyup.enter.native="handleQuery"></el-option>
          <el-option label="关闸" value="1" @keyup.enter.native="handleQuery"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="设备ip" prop="driverIp">
        <el-input
          v-model="queryParams.driverIp"
          placeholder="请输入设备ip"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">刷新</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['sys-record:record:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordList">
      <el-table-column label="序号" align="center" prop="corid" />
      <el-table-column label="物业名称" align="center" prop="propertyManagement.propertyName" />
      <el-table-column label="车场名称" align="center" prop="carsHome.chname" />
      <el-table-column label="设备ip" align="center" prop="driverIp" />
      <el-table-column label="开关类型" align="center" prop="off" :formatter="offNo"/>
      <el-table-column label="出入口" align="center" prop="gate" :formatter="getecos"/>
      <el-table-column label="相机品牌" align="center" prop="camera" />
      <el-table-column label="操作人" align="center" prop="cutoffUser" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="备注" align="center" prop="cutoffRemark" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listRecord, getRecord, delRecord, addRecord, updateRecord } from "@/api/pxy-cars/record";
import { listHome, getHome, delHome, addHome, updateHome } from "@/api/pxy-cars/home";
import { listManagement, getManagement, delManagement, addManagement, updateManagement } from "@/api/pxy-cars/management";

export default {
  name: "Record",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 开闸记录表格数据
      recordList: [],
      carsHome:[],
      carsManagement: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        status: null,
        deleted: null,
        driverIp: null,
        cutoffRemark: null,
        cutoffUser: null,
        pmid: null,
        hpid: null
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
    this.getHome();
    this.getManagement();
  },
  methods: {
    /** 查询开闸记录列表 */
    getList() {
      this.loading = true;
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        console.log(response)
        this.total = response.total;
        this.loading = false;
      });
    },
    getHome() {
      this.loading = true;
      listHome(this.queryParams).then(response => {
        this.carsHome = response.rows;
        // console.log(response.rows)
        this.loading = false;
      });
    },
    getManagement() {
      this.loading = true;
      listManagement(this.queryParams).then(response => {
        this.carsManagement = response.rows;
        // console.log(response.rows)
        this.loading = false;
      });
    },
    offNo(row, col) {
      return row.off === 0 ? '开闸' : '关闸'
    },
    getecos(row, col){
      return row.gate === 1 ? '入口' : '出口'
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        corid: null,
        code: null,
        status: null,
        deleted: null,
        createTime: null,
        updateTime: null,
        driverIp: null,
        cutoffRemark: null,
        cutoffUser: null,
        pmid: null,
        hpid: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pxy-cars/record/export', {
        ...this.queryParams
      }, `record_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
